﻿using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;

using Finance.Entites;
using Finance.Service.Interfaces;

namespace Finance.Service.Implements
{
    /// <summary>
    /// Store the data with json format in the disk
    /// </summary>
    /// <typeparam name="TEntity">The graph of store object contains in ObserableCollection</typeparam>
    public class MockSettingDataStore : JsonDataStore<Setting>
    {
        private static ObservableCollection<Setting> _SettingCollections = new ObservableCollection<Setting>();

        public override ObservableCollection<Setting> Items
        {
            get
            {
                if (base.Items == null || base.Items.Count == 0)
                {
                    _SettingCollections.Clear();
                    var settingGroups = new List<Setting>()
                    {
                        new Setting()
                        {
                            AccountName = new MockAccountDataStore().Items.First().Name,
                            IncomeClassificationName = new MockIncomeClassificationDataStore().Items.First().Name,
                            PayoutClassificationName = new MockPayoutClassificationDataStore().Items.First().Name,
                            ProjectName = new MockProjectDataStore().Items.First().Name,
                            TraderName = new MockTraderDataStore().Items.First().Name,
                            SecurityStatus = false
                        }
                    };
                    foreach (var settingGroup in settingGroups)
                    {
                        _SettingCollections.Add(settingGroup);
                    }
                    base._Items = _SettingCollections;
                    base.Commit();
                }

                return _Items;
            }
        }
    }
}
